#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e4+100;
typedef long long LL;
LL a[maxn];
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL n,k;cin>>n>>k;
  for(LL i=1;i<=n;i++) cin>>a[i];
  sort(a+1,a+1+n);
  LL ans=1;
  for(LL i=1;i<=n;i++){
        LL pos=upper_bound(a+1,a+1+n,a[i]+k)-a;
    ///    debug(pos);
        if(pos==n+1){
            ans=max(ans,n-i+1);
        }
        else{
            if(a[pos]-a[i]>k){
                pos--;
                ans=max(ans,pos-i+1);
            }
        }
  }
  cout<<ans<<endl;
return 0;
}
